package com.ticket.sass.ticketserver.dto.output

import io.swagger.annotations.ApiModelProperty

data class ResultWrapOutput<T>(
    @ApiModelProperty(value = "状态码：0 成功，1 失败", required = true)
    val code: Int = Code.OK.value,

    @ApiModelProperty(value = "提示信息", required = true)
    val message: String = "",

    @ApiModelProperty(value = "错误码", required = true)
    val errorCode: String = ErrorCode.OK.value,

    @ApiModelProperty(value = "错误信息", required = true)
    val errorMessage: String = "",

    @ApiModelProperty(value = "数据", required = true)
    val data: T? = null
) {
    companion object {
        fun <T>success(data: T? = null): ResultWrapOutput<T> {
            return ResultWrapOutput(data = data)
        }

        fun error(errorCode: ErrorCode): ResultWrapOutput<Any?> {
            return ResultWrapOutput(
                Code.ERROR.value,
                errorCode.reasonPhrase,
                errorCode.value,
                errorCode.reasonPhrase
            )
        }
    }

    enum class Code(val value: Int) {
        OK(0),
        ERROR(1)
    }

    enum class Series(val value: String) {
        OK("0"),
        CLIENT("A"),
        SERVER("B"),
        PLATFORM("C")
    }

    enum class ErrorCode(val value: String, val series: Series, val reasonPhrase: String) {
        OK("", Series.OK, "OK"),

        // A系列 - 通用
        CLIENT_ERROR("A0001", Series.CLIENT, "用户端出错"),
        UNAUTHORIZED("A0002", Series.CLIENT, "访问无权限"),
        BAD_REQUEST("A0200", Series.CLIENT, "请求参数有误"),
        SERVER_ERROR("A0300", Series.SERVER, "服务端出错"),
        CONFIG_ERROR("A0400", Series.SERVER, "配置有误"),
        PLATFORM_ERROR("A0500", Series.SERVER, "第三方交互出错"),

        // B系列 - 影票接口
        B_TIMEOUT("B0100", Series.PLATFORM, "请求超时，请重试"),
    }
}
